from flask import jsonify

def success_response(data=None, message='操作成功', code=200):
    """成功响应"""
    response = {
        'code': code,
        'message': message,
        'data': data
    }
    return jsonify(response), code

def error_response(message='操作失败', code=400, data=None):
    """错误响应"""
    response = {
        'code': code,
        'message': message,
        'data': data
    }
    return jsonify(response), code

def paginated_response(items, total, page, per_page, message='获取成功'):
    """分页响应"""
    data = {
        'items': items,
        'total': total,
        'page': page,
        'per_page': per_page,
        'pages': (total + per_page - 1) // per_page
    }
    return success_response(data, message) 